import 'package:flutter/material.dart';
import 'package:flutter_09_game/base/widget/base_get_builder.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/pages/promotion/promotion_commission/promotion_commission_logic.dart';
import 'package:flutter_09_game/user/app_user_manager.dart';
import 'package:flutter_09_game/utils/utils_other.dart';
import 'package:flutter_09_game/widgets/appbar/common_app_bar.dart';
import 'package:flutter_09_game/widgets/btn_dropdown.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_09_game/widgets/tab/common_tab_bar_page.dart';
import 'package:flutter_09_game/widgets/tab/custom_tab_indicator.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../config/app_color.dart';
import 'promotion_logic.dart';

class PromotionPage extends StatelessWidget {
  PromotionPage({super.key});

  final PromotionLogic logic = Get.put(PromotionLogic());

  @override
  Widget build(BuildContext context) {
    return BaseGetBuilder<PromotionLogic>(
      appBar: CommonAppBar(
        title: LocaleKeys.promotionAgent.tr,
        showBack: false,
        actions: [
          Obx(() {
            // tabIndex
            return Visibility(
                visible: logic.currentTabIndex.value == 0,
                child: BtnDropdown(
                    items: AppUserManager()
                        .walletList
                        .map((item) => item.symbol ?? '')
                        .toList(),
                    value: AppUserManager().currentWalletRx.value.symbol ?? '',
                    onChanged: (newValue) {
                      AppUserManager().selectUserWallet(newValue);
                      if (Get.isRegistered<PromotionCommissionLogic>()) {
                        Get.find<PromotionCommissionLogic>().refreshList();
                      }
                      // setState(() => selectedCoin = newValue);
                    },
                    child: Container(
                        padding: EdgeInsets.all(8.w),
                        decoration: BoxDecoration(
                          color: AppColor.textPrimary.withOpacity(0.05),
                          borderRadius: BorderRadius.circular(8.w),
                          border: Border.all(
                              color: AppColor.textPrimary.withOpacity(0.15),
                              width: 1),
                        ),
                        child: Obx(() {
                          return Row(
                            children: [
                              AutoImage(
                                UtilsOther().getAmountTagIcon(AppUserManager()
                                    .currentWalletRx
                                    .value
                                    .symbol),
                                width: 24.w,
                              ),
                              4.horizontalSpace,
                              Text(
                                AppUserManager().currentWalletRx.value.symbol ??
                                    '',
                                style: TextStyle(
                                    fontWeight: FontWeight.w500,
                                    fontSize: 14.sp,
                                    color:
                                        AppColor.textPrimary.withOpacity(0.94)),
                              ),
                              4.horizontalSpace,
                              AutoImage(
                                Assets.commonDownArrow,
                                width: 16.w,
                              ),
                            ],
                          );
                        }))));
          }),
          16.horizontalSpace,
        ],
      ),
      // backgroundColor: ,
      builder: (_) {
        return CommonTabBarPage(
            tabIsScrollable: false,
            tabBarPadding: EdgeInsets.zero,
            labelPadding: EdgeInsets.zero,
            tabController: logic.tabController,
            indicatorSize: TabBarIndicatorSize.tab,
            backgroundColor: AppColor.navBgColor,
            keepView: false,
            // fitTabBackgroundColor: Colors.red,
            tabBarHeight: 50.w,
            // tabBarPadding: ,
            indicator: CustomTabIndicator(
              width: 98.w,
              height: 2.w,
              indicatorPadding: EdgeInsets.only(top: -4.w),
              color: AppColor.primary,
              // borderRadius: 2.w,
              isCentered: true,
            ),
            tabData: logic.tabData);
      },
    );
  }
}
